const http =require('http');
const mysql = require('mysql2');

const server = http.createServer((req,res)=>{
    if (req.url === '/users') {
        //链接数据库 查询数据库 返回数据给前端
        const connection = mysql.createConnection({
            host: 'localhost',
            user: 'root',
            database: 'demo',
            password: '123456789'
          });
          connection.query(
            'SELECT * FROM `users` ',
            function (err, results, fields) {
              console.log(results); // 结果集
            
            }
          );
    }
    res.end('Hello World');
});
server.listen(3000,()=>{
    console.log('Server is running on port 3000');
});